/*
 * Circle.cpp
 *
 *  Created on: 28/ott/2013
 *      Author: angelo
 */

#include "Circle.h"

Circle::Circle() {
	p = Coordinates::ZERO;
	r = 0;
}

Circle::Circle(const Circle& circle) {
	p = circle.p;
	r = circle.r;
}

Circle::Circle(Coordinates center, double radius) {
	p = center;
	r = radius;
}

Circle::Circle(Coordinates center) {
	p = center;
	r = 0;
}

Circle::Circle(Coordinates p1, Coordinates p2) {
	p = p1.midPoint(p2);
	r = p1.distance(p);
}

Circle::Circle(Coordinates p1, Coordinates p2, Coordinates p3) {
	double x = (	(p3.x*p3.x * (p1.y-p2.y)) +
					(p1.x*p1.x + (p1.y-p2.y)*(p1.y-p3.y)) * (p2.y-p3.y) +
					(p2.x*p2.x * (-p1.y+p3.y)) )
						/ (2 * (p3.x * (p1.y-p2.y) + p1.x * (p2.y-p3.y) + p2.x * (-p1.y+p3.y)));
	double y = (p2.y+p3.y)/2 - (p3.x - p2.x)/(p3.y-p2.y) * (x - (p2.x + p3.x)/2);
	p = Coordinates(x, y);
	r = p.distance(p1);
}

Circle::~Circle() {
	// TODO Auto-generated destructor stub
}

// Is a point in the circle
int Circle::contain(Coordinates point)
{
	int answer = 0;
	double d = p.distance(point);
	if (d > r)
	{
		answer = 1;		// The point is outside the circle
	}
	else if (d == r)
	{
		answer = 0;		// The point is on the circumference of the circle
	}
	else
	{
		answer = -1;	// The point is inside the circle
	}
	return answer;
}

